# 1 使用requests库session机制，实现 tpshop前台用户注册，并注册账号成功。
# 分析步骤：
# 1。创建Session实例
# 2。使用Session实例，发送获取验证码请求
# 3。使用session实例，发送注册请求
import requests


class TestRegister:
    # 注册成功
    # def test_reg_pass(self):
    #     reg_session = requests.Session()
    #     reg_session.get(url="http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify&type=user_reg")
    #     reg_url = "http://hmshop-test.itheima.net/Home/User/reg.html"
    #     reg_header = {"Content-Type":"application/x-www-form-urlencoded"}
    #     reg_body = {
    #         "auth_code" : "TPSHOP" ,
    #         "scene" : "1" ,
    #         "username" : "14712341099" ,
    #         "verify_code" : "8888" ,
    #         "password" : "90600d68b0f56d90c4c34284d8dfd138" ,
    #         "password2" : "90600d68b0f56d90c4c34284d8dfd138"
    #     }
    #     resp_reg = reg_session.post(url = reg_url,headers = reg_header,data=reg_body)
    #     assert 1 == resp_reg.json()['status']
    #     assert "注册成功" == resp_reg.json()['msg']

    # 注册失败--手机号已存在
    # def test_reg_fail_001(self):
    #     reg_session = requests.Session()
    #     reg_session.get(url="http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify&type=user_reg")
    #     reg_url = "http://hmshop-test.itheima.net/Home/User/reg.html"
    #     reg_header = {"Content-Type": "application/x-www-form-urlencoded"}
    #     reg_body = {
    #         "auth_code": "TPSHOP",
    #         "scene": "1",
    #         "username": "14792291009",
    #         "verify_code": "8888",
    #         "password": "90600d68b0f56d90c4c34284d8dfd138",
    #         "password2": "90600d68b0f56d90c4c34284d8dfd138"
    #     }
    #     resp_reg = reg_session.post(url=reg_url, headers=reg_header, data=reg_body)
    #     assert -1 == resp_reg.json()['status']
    #     assert "该手机号已注册" == resp_reg.json()['msg']

#     注册失败：两次密码不一样
    def test_reg_fail_001(self):
        reg_session = requests.session()
        reg_session.get("http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify&type=user_reg")
        reg_url = "http://hmshop-test.itheima.net/Home/User/reg.html"
        reg_header = {"Content-Type":"application/x-www-form-urlencoded"}
        reg_body = {
                "auth_code": "TPSHOP",
                "scene": "1",
                "username": "14792291009",
                "verify_code": "8888",
                "password": "90600d68b0f56d90c4c34284d8dfd138000000000",
                "password2": "90600d68b0f56d90c4c34284d8dfd138"
        }
        resp_reg = reg_session.post(url = reg_url,headers= reg_header,data =reg_body)
        print(resp_reg.json())